package com.yanqu.road.dao.impl.activity.huashigang;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangActivityEventConfig;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangFloorConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author wpj
 * @Date 2020/10/5
 */
public class HuaShiGangActivityDaoImpl extends TempDao {

    public static String getHuaShiGangActivityEventConfigSql = "select * from t_s_activity_huashigang_event where activityId = ?";
    public Map<Integer, HuaShiGangActivityEventConfig> getHuaShiGangActivityEventConfig(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, HuaShiGangActivityEventConfig> map = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHuaShiGangActivityEventConfigSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HuaShiGangActivityEventConfig huaShiGangActivityEventConfig = new HuaShiGangActivityEventConfig();
                huaShiGangActivityEventConfig.setActivityId(rs.getInt("activityId"));
                huaShiGangActivityEventConfig.setEventId(rs.getInt("eventId"));
                huaShiGangActivityEventConfig.setEventType(rs.getInt("eventType"));
                huaShiGangActivityEventConfig.setIcon(rs.getString("icon"));
                huaShiGangActivityEventConfig.setNpcId(rs.getInt("npcId"));
                huaShiGangActivityEventConfig.setWeight(rs.getInt("weight"));
                huaShiGangActivityEventConfig.setName(rs.getString("name"));
                huaShiGangActivityEventConfig.setDesc(rs.getString("desc"));
                huaShiGangActivityEventConfig.setRewards(rs.getString("rewards"));
                if (huaShiGangActivityEventConfig.getRewards().equals("0")) {
                    huaShiGangActivityEventConfig.setRewards("");
                }
                huaShiGangActivityEventConfig.setParamList(rs.getString("paramList"));
                map.put(huaShiGangActivityEventConfig.getEventId(), huaShiGangActivityEventConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    public static String getHuaShiGangFloorConfigSql = "select * from t_s_activity_huashigang_floor where activityId = ? order by floor asc";
    public Map<Integer, HuaShiGangFloorConfig> getHuaShiGangFloorConfig(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, HuaShiGangFloorConfig> map = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHuaShiGangFloorConfigSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HuaShiGangFloorConfig huaShiGangFloorConfig = new HuaShiGangFloorConfig();
                huaShiGangFloorConfig.setActivityId(rs.getInt("activityId"));
                huaShiGangFloorConfig.setFloor(rs.getInt("floor"));
                huaShiGangFloorConfig.setSpecialReward(rs.getString("specialReward"));
                huaShiGangFloorConfig.setRewards(rs.getString("rewards"));
                huaShiGangFloorConfig.setConsume(rs.getString("consume"));
                map.put(huaShiGangFloorConfig.getFloor(), huaShiGangFloorConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
